package cn.itcast.controller;

import cn.itcast.domain.Courier;
import cn.itcast.service.CourierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.*;

@Controller
public class CourierController {

    @Autowired
    private CourierService courierService;
    @RequestMapping("/courier_save")
    public String save(Courier courier){
        courierService.save(courier);
        return "redirect:/pages/base/courier.html";
    }
    @RequestMapping("/courier_pageQuery")
    @ResponseBody
    public Map pageQuery(Courier courier,int page, int rows){
        //System.out.println(page+"   "+rows);
        HashMap map = new HashMap();
        Page<Courier> pageQuery = courierService.pageQuery(courier,page, rows);
        map.put("total",pageQuery.getTotalElements());
        map.put("rows",pageQuery.getContent());
        return map;
    }
    @RequestMapping("/courier_delBatch")
    public String delBatch(@RequestParam(value = "ids")String ids){
        System.out.println("ids = " + ids);
        String[] idArr = ids.split(",");
        List<String> list = Arrays.asList(idArr);
        courierService.delBatch(list);
        return "redirect:/pages/base/courier.html";


    }

    @RequestMapping("/courier_restore")
    public String restore(@RequestParam(value = "ids")String ids){
        System.out.println("ids = " + ids);
        String[] idArr = ids.split(",");
        List<String> list = Arrays.asList(idArr);
        courierService.restore(list);
        return "redirect:/pages/base/courier.html";


    }

}
